//
//  AllParticipateRecordsViewController.m
//  lmq
//
//  Created by 马田成 on 2017/4/3.
//  Copyright © 2017年 yuanxin. All rights reserved.
//

#import "AllParticipateRecordsViewController.h"
#import "AllParticipateRecordsTableViewCell.h"
#import "ToolAboutTime.h"
#import "UIImageView+WebCache.h"

@interface AllParticipateRecordsViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;


@end

@implementation AllParticipateRecordsViewController
//参与记录
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    [self regeditCell];
    [self creationDate];
    
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    self.navigationItem.title = @"参与记录";
    self.tableView = [[UITableView alloc] init];
    
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64);
    //    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}
- (void)regeditCell{
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"AllParticipateRecordsTableViewCell" bundle:nil] forCellReuseIdentifier:@"AllParticipateRecordsTableViewCell"];
    
}
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 70;
    
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    AllParticipateRecordsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AllParticipateRecordsTableViewCell" forIndexPath:indexPath];
    
    NSMutableDictionary *dict = self.dataArr[indexPath.row];
    
    cell.nameLabel.text = [dict objectForKey:@"user_name"];
    cell.num.text = [dict objectForKey:@"num"];
    cell.timeLabel.text = [ToolAboutTime getTimeStrByTimeSp:[dict objectForKey:@"add_time"]];
    
//    NSString *strPic = @"http://lmq.quyum.cn/";
//    
//    NSString *str = [strPic stringByAppendingString:[dict objectForKey:@"header_img"]];
    
    NSString *urlWare=[dict objectForKey:@"header_img"];
    NSString *urlN=manage(AP_HOST, urlWare);
    NSString *strUrl = [urlN stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    
    [cell.img sd_setImageWithURL:[NSURL URLWithString:strUrl]];
    [cell.img sd_setImageWithURL:[NSURL URLWithString:strUrl] placeholderImage:[UIImage imageNamed:@"liyi"]];
    
    
    
    
    return cell;
    
    
    
    
}
- (void)creationDate{
    
    _dataArr = [[NSMutableArray alloc]init];
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];

    [productParams setValue:self.shop_id forKey:@"shop_id"];
    [productParams setValue:self.stage forKey:@"stage"];
    
    [[MNetworkHandler sharedInstance]conURL:Home_OneshowallParticipation
                                networkType:NetWorkPOST
                                     params:productParams
                                   delegate:nil
                                    showHUD:NO
                               successBlock:^(id returnData) {
                                   if ([[returnData objectForKey:@"code"]intValue]==1) {
                                       
                                       _dataArr=[returnData objectForKey:@"data"];
                                       ;
                                       
                                       
                                       
                                       //                                       for (NSDictionary *dic in dict1 ) {
                                       //                                           MyRefoundOneModel *model = [[MyRefoundOneModel alloc]init];
                                       //
                                       //                                           [model setValuesForKeysWithDictionary:dic];
                                       //                                           [_dataArr addObject:model];
                                       //                                       }
                                       
                                       
                                       [self.tableView reloadData];
                                   }
                                   else {
                                       [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
                                   }
                               } failureBlock:^(NSError *error) {
                                   NSLog(@"%@",error);
                                   [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
                               }];
    
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
